package com.juzipi.demo;

import org.joda.time.DateTime;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * @Author juzipi
 * @Date 2021/5/11 20:27
 * @Info
 */
public class TestDate {

    public static void main(String[] args) throws ParseException {
//        System.out.println(dateToWeek("2021-5-10"));

        String stringDate = "Thu Oct 16 07:13:48 GMT 2015";
        Date parse = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("ENGLISH", "CHINA")).parse(stringDate);
        String format = new SimpleDateFormat("yyyy-mm-dd").format(parse);
        System.out.println(format.toString());
        System.out.println(format);

        String s = "The Jul 22 23:58:32 CST 2013";
        String time = "Wed Oct 14 00:00:00 CST 2020";
        String times = "2021-2-10";
        DateTime dateTime = new DateTime(times);
        System.out.println("dateTime:"+dateTime);
//        Date date = dateTime.toDate();
//        System.out.println(date);
//        DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy", Locale.US);
//        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Date parse1 = df.parse(s);
//        System.out.println(sdf.parse(parse1.toString()));



    }




    private static String dateToWeek(String datetime) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar calendar = Calendar.getInstance();
        Date date;
        try {
            date = simpleDateFormat.parse(datetime);
            calendar.setTime(date);
        } catch (ParseException e) {
            throw new RuntimeException("报错啦");
        }
        //一周的第几天
        int w = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }
}
